const webpack = require('webpack');
const wdm = require('webpack-dev-middleware');
const path = require('path');
let target = path.resolve(__dirname, 'dist');
// const express = require('express');
const connect = require('connect');
const HtmlWebpackPlugin = require('html-webpack-plugin');

const compiler = webpack({
    mode: 'development',
    entry: {
        app: './app.js'
    },
    output: {
        path: target,
        chunkFilename: '[name].[chunkhash].js',
        publicPath: '/test',
    },
    plugins: [
        new HtmlWebpackPlugin()
    ]
});

const app = connect();
let wdmOptions = {
    publicPath: '/test',
    writeToDisk: false,
    mimeTypes: {
        test: 'x/test'
    }
};
var wdmFn = wdm(compiler, wdmOptions);
// let filename = wdmFn.getFilenameFromUrl({
//     options: wdmOptions
// });
wdmFn.waitUntilValid(()=>{
    console.log('Package is in a valid state');
});
app.use(wdmFn);
// console.log(`filename: ${filename}`);
app.listen(3000, ()=>{
    console.log(`Example app listening on port 3000!`);
})

setTimeout(()=>{
    wdmFn.invalidate();
}, 1000);